package com.example.mananger.component;

import com.example.base.security.SysUser;
import com.example.base.security.util.SecurityUtil;
import com.example.base.system.domain.SysApi;
import com.example.base.system.domain.SysRoleApi;
import com.example.base.system.service.SysApiService;
import com.example.base.system.service.SysRoleApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ApiHandlerComponent implements CommandLineRunner {



    @Autowired
    private SysRoleApiService sysRoleApiService;

    @Autowired
    private SysApiService sysApiService;

    public boolean handler(String path){
      SysApi sysApi=sysApiService.getSysApiByUrl(path);
      if(sysApi==null){
          return true;
      }
      SysUser sysUser=SecurityUtil.getSelfUserEntity();
      SysRoleApi sysRoleApi=sysRoleApiService.getSysRoleApiByRoleIdAndApiId(sysUser.getRoleId(),sysApi.getId().toString());
      return  sysRoleApi!=null;
    }

    @Override
    public void run(String... args) throws Exception {

    }
}
